/*********************************************************************\
*
*                  (c) lkc
*                  All Rights Reserved. lkc Confidential
*
\*********************************************************************/
/*********************************************************************\
*   Title                      :
*
*   Module Description         :
*
*   Author                     : lkc
*
*   Created                    : 2017-7-12
*
\*********************************************************************/
#include <chrono>
#include <fcntl.h>

#include <QDebug>
#include <thread>

#include "CamControl.h"
#include "ProtocolMCU.h"
#include "UtilityTH.h"
#include "GpioManage.h"
#include "CamGainControl.h"
#include "DisplayControl.h"

#include "FocusControl.h"

CamControl CamControl::m_Instance;

CamControl::CamControl()
{
}

CamControl& CamControl::GetInstance()
{
    return m_Instance;
}

void CamControl::SetWorkMode(bool mode)
{
//    if(m_workMode==mode)
//    {
//        return;
//    }
    if(mode)
    {
        OpenCCDPower();
        OpenMotoPower();
        EnableDisplay();
    }
    else
    {
        CloseCCDPower();
        CloseMotoPower();
        DisableDisplay();
    }
    focusCtl.SetWorkModeSignal(mode);
    m_workMode = mode;
}

bool CamControl::GetWorkMode()
{
    return m_workMode;
}

void CamControl::OpenCCDPower()
{
    DebugPrintf("Open CCDPower.\n");
    GpioManage::GetInstance().IoWrite(GpioPinNum::CCD_POWER_IO,IoValue::HIGH);
}

void CamControl::CloseCCDPower()
{
    DebugPrintf("Close CCDPower.\n");
    GpioManage::GetInstance().IoWrite(GpioPinNum::CCD_POWER_IO,IoValue::LOW);
}

void CamControl::OpenMotoPower()
{
    DebugPrintf("Open MotoPower.\n");
    GpioManage::GetInstance().IoWrite(GpioPinNum::MOTO_POWER_IO,IoValue::HIGH);
}

void CamControl::CloseMotoPower()
{
    DebugPrintf("Close MotoPower.\n");
    GpioManage::GetInstance().IoWrite(GpioPinNum::MOTO_POWER_IO,IoValue::LOW);
}

void CamControl::PALReset()
{
    GpioManage::GetInstance().IoWrite(GpioPinNum::ADV7180_PAL_RESET,IoValue::LOW);
    std::this_thread::sleep_for(std::chrono::milliseconds(20));
    GpioManage::GetInstance().IoWrite(GpioPinNum::ADV7180_PAL_RESET,IoValue::HIGH);
}

void CamControl::PALSetNormal()
{
    GpioManage::GetInstance().IoWrite(GpioPinNum::ADV7180_PAL_RESET,IoValue::HIGH);
}

void CamControl::InitCamera()
{
    DebugPrintf("Init Camera\n");
//    PALReset();
    PALSetNormal();
    SetWorkMode(true);
    SetVideoRecordSate(false);
}

void CamControl::SetVideoRecordSate(bool recordState)
{
    m_videoRecordSate = recordState;
}

bool CamControl::GetVideoRecordSate()
{
    return m_videoRecordSate;
}


/********************************************************************\
 *
 * REVISION RECORDS
 *
\*********************************************************************/
/*********************************************************************/
/*
 *
 *
 *
\*********************************************************************/
/*------------------------------The End------------------------------*/









